<template>
    <mi-form-page @submit="submit"
                  :loading="edit.loading"
                  v-model:show="edit.show"
                  title="积分配置"
    >
        <el-form :model="edit.info"
                 :rules="rules"
                 ref="formRef">

            <el-form-item prop="is_on" label="开启积分功能">
                <mi-radio v-model="edit.info.value.is_on" />
            </el-form-item>
            <el-form-item prop="is_on_dec" label="开启下单积分抵扣">
                <mi-radio v-model="edit.info.value.is_on_dec" />
            </el-form-item>

            <el-form-item prop="money_rate" label="积分抵扣比例">
                <mi-input-number v-model="edit.info.value.money_rate" />
                <mi-form-aux>抵扣1元人民币所需要的积分数量</mi-form-aux>
            </el-form-item>

            <el-form-item prop="give_points_rate" label="消费积分赠送比例">
                <mi-input-number v-model="edit.info.value.give_points_rate" />
                <mi-form-aux>每消费1元赠送的积分数量，设置为0则不赠送积分</mi-form-aux>
            </el-form-item>

        </el-form>
    </mi-form-page>
</template>

<script setup lang="ts">
import {ref, onBeforeMount, inject, computed, watch} from "vue";
import {simpleGet} from "@/utils/request";
import {FormInstance} from "element-plus";
import Edit from "@/model/edit";

const url = '/site.siteConfig/edit'

const rules = {

}

const loading = ref(false)
const formRef = ref<FormInstance>()
const parentOptions = ref<any[]>([])
const edit = inject('points', new Edit({}))
edit.info = {value:{}}

const submit = () => {
    edit.submit({
        formRef: formRef.value,
        url: url,
    })
}


watch(() => edit.show, (nv, ov) => {
    if (nv){
        edit.init(async () => {
            let {info} = await simpleGet(url, {key:'points'})
            edit.info = info
        })
    }
})


</script>

<style scoped>

</style>

